<?php
//------------------------------------------------------------------------------
// Class              : Ctl_DownloadDriver
// Modification       :
//------------------------------------------------------------------------------
// Date(yyyy.mm.dd)   Developer                       Action
//------------------------------------------------------------------------------
// 2008.01.21          Oanhhtk                         Created
//------------------------------------------------------------------------------

class Ctl_Download extends ControlBase{
    var $modul="download";
    //==========================================================================
    // Function    : Ctl_DownloadDriver
    // Creator     : Oanhhtk 2007.03.15
    // Details     : Call the constructor of father class to initial variable
    //==========================================================================
    function Ctl_Download(){
         // Constructor of father class.
         ControlBase::ControlBase();
    }

    //==========================================================================
    // Function    : execute
    // Creator     : Oanhhtk 2007.03.15
    // Details     : Execute the process depend the given mode, 
    //               as: Add, Delete, Edit and default is List.
    //==========================================================================
     function execute($action=""){
        global $db, $arrayError, $_POST;
        $arrayData =  array();
		$arrayData2 = array();
        // Get back the work you want to do.
        $this->modul = CM_getParameter(MODUL);
        if ($action==""){
            // Get back the action: as: Add, Delete, Edit or List.
             $action = CM_getParameter(ACTION);
        }
        
        // Get data
        include_once(DIR_MODEL."md_download_bao_gia.class.php");
        $objDownload = new MD_DownloadBaogia($this->db);
        
        switch($action){  
			 case "View":
                 // Get a record with given id
                 $id = CM_getParameter("id");
				
                 $arrayData = $objDownload->getById($id);
				 
                 // Error processing
                 if(empty($arrayData)){
                    $arrayError[]=$LANG["error"]["khong_tim_thay_ban_ghi"];//"Không tìm thấy bản ghi.";// nào có id=".$id;
                 } 
                 // Show data
				 $arrayData2 = $objDownload->getByWhere("*","id<>'".$id."'","ngay_tao desc");
				 //$this->includeFileLang("l_info_view.php");
                 include_once(DIR_VIEW."v_tin_tuc_view.php");                   
                 V_TintucView(&$arrayData,&$arrayData2,"View");
                 // update SoLanXem + 1
                $objDownload->updateSoLanXem($id);       
                 break; 
			case "List":
			default :{
				$arrayData = $objDownload->getByWhere("*","hien_thi = 1","ngay_dang desc");
				
				 // Show data
				// $this->includeFileLang("l_info_view.php");				 
                 include_once(DIR_VIEW."v_download_list.php");                   
                 V_DownloadList(&$arrayData,"List");
                 // update SoLanXem + 1
                //$objDownload->updateSoLanXem($id);       
                 break; 
			}            
        }
        unset($arrayData,$arrayData2);
    }      
} 
?>